//分类数据模块
//数据操作模块
var sqlHelper=require('../conf/sqlHelper');

//分类方法
function getCategroyByUpId(up_id,callback) {
	// body...
	var sqlstr='select * from shop_category where up_id=?';
    var param=[up_id];

    sqlHelper.ExecuteReader(sqlstr,param,function(results){
    	if(results){
    		callback(results);
    	}    		
    });
}

//获取所有分类
function getCategoryAll(callback){
	var sqlstr='select * from shop_category';    

    sqlHelper.ExecuteReader(sqlstr,null,function(results){
    	if(results){
    		callback(results);
    	}    		
    });
}

//修改分类方法
function modifyCategoryById(cate_id,cate_name,up_id,callback) {
	// body...
	var sqlstr='update shop_category set category_name=?,up_id=? where category_Id=?';
    var param=[cate_name,up_id,cate_id];

    sqlHelper.ExecuteUpdate(sqlstr,param,function(results){
    	if(results){
    		callback(results);
    	}    		
    });
}

//添加方法
function insertCategoryById(up_id,cate_name,callback) {
	// body...
	var sqlstr='insert into shop_category(up_id,category_name)values(?,?)';
    var param=[up_id,cate_name];

    sqlHelper.ExecuteUpdate(sqlstr,param,function(results){
    	if(results){
    		callback(results);
    	}    		
    });
}

exports.getCategroyByUpId=getCategroyByUpId;
exports.getCategoryAll=getCategoryAll;
exports.modifyCategoryById=modifyCategoryById;
exports.insertCategoryById=insertCategoryById;
